<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 示例接口
 */
class Auto extends Api
{

    //如果$noNeedLogin为空表示所有接口都需要登录才能请求
    //如果$noNeedRight为空表示所有接口都需要验证权限才能请求
    //如果接口已经设置无需登录,那也就无需鉴权了
    //
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['test2'];

    protected function string_decrypt1($encryptedData, $screct_key) {
		// AES, 128 模式加密数据 CBC
		$encryptedData = strtr($encryptedData, '-_', '+/');
		$encryptedDataBase64Decoded = base64_decode(trim($encryptedData));
// 		$screct_key = base64_decode($screct_key);
		// 设置全0的IV
		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
		$iv = str_repeat("\0", $iv_size);
		$decrypt_str = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $screct_key, $encryptedDataBase64Decoded, MCRYPT_MODE_ECB, $iv));
		$decrypt_str = self::stripPKSC7Padding($decrypt_str);
		return $decrypt_str;
	}
	
	/**
	 * 移去填充算法
	 *
	 * @param string $source
	 * @return string
	 */
	protected function stripPKSC7Padding($source) {
		$char = substr($source, - 1);
		$num = ord($char);
		if( $num == 62 )
			return $source;
		$source = substr($source, 0, - $num);
		return $source;
	}

    public function test(){

            
            // 测试解密
            $strr = '8n/t4o02wx4QqsHu/Y+JGfBto9iQngIBUVzOmm+ItRDt1cKemLgE/snVA3RKRbP1';
            $two_data = $this->string_decrypt1($strr, 'oe4kY78y5NjvpgK0');
           
    }
  
  

}